;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

public class Main {

    public static void main(String[] args) {

        //HTTP请求.

        try {
            //根据UTF-8编码格式,将 张三 转换为  ASC 编码
            String zs = URLEncoder.encode("钢铁锅", "UTF-8");
            String as = URLEncoder.encode("含着泪含修瓢锅", "UTF-8");
//            System.out.println(zs);
            String address = "http://192.168.3.159:8080/home/test?name=" + zs + "&psw="+as;
            //创建网址对象
            URL url = new URL(address);
            //使用网址打开连接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            //设置请求方式 GET/POST
            conn.setRequestMethod("GET");
            //设置请求超时时间 10000毫秒

            conn.setConnectTimeout(10000);

            /**判断请求是否成功?***/
            //获取请求码
            int responseCode = conn.getResponseCode();
            System.out.println("responseCode:" + responseCode);
            if (responseCode ==HttpURLConnection.HTTP_OK) {
                System.out.println("请求成功!");

                //获取服务器返回的数据
                InputStream is = conn.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                String line = br.readLine();
                System.out.println("服务器返回的数据为:>>>> " + line);
            } else {
                System.out.println("请求失败");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
